<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
      <el-form :inline="true" :model="filters" :size="size" ref="filters" label-width="120px">
        <el-form-item prop="ordernumber" label="订单编号">
          <el-input v-model="filters.ordernumber" placeholder="订单编号"></el-input>
        </el-form-item>
        <el-form-item prop="bname"  label="商家名称">
          <el-input v-model="filters.bname" placeholder="商家名称"></el-input>
        </el-form-item>
        <el-form-item prop="customername" label="客户名称">
          <el-input v-model="filters.customername" placeholder="客户名称"></el-input>
        </el-form-item>
        <el-form-item prop="productname" label="商名名称">
          <el-input v-model="filters.productname" placeholder="商名名称"></el-input>
        </el-form-item>
        <el-form-item prop="recipient" label="收件人">
          <el-input v-model="filters.recipient" placeholder="收件人"></el-input>
        </el-form-item >
        <el-form-item prop="startTime" v-if="false">
          <el-input v-model="filters.startTime"></el-input>
        </el-form-item>
        <el-form-item prop="endTime" v-if="false">
          <el-input v-model="filters.endTime" ></el-input>
        </el-form-item>
        <el-form-item prop="status" label="发送状态">
          <el-select v-model="filters.status"  placeholder="发送状态" style="width:200px">
            <el-option label="全部" value=""></el-option>
            <el-option label="全部发货" value="全部发货"></el-option>
            <el-option label="未发货" value="未发货"></el-option>
            <el-option label="部分发货" value="部分发货"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="time" label="订单时间">
          <el-date-picker
            v-model="filters.time"
            type="daterange" value-format="yyyy-MM-dd"
            @change="chooseTimeRange"
            range-separator="至"
            start-placeholder="创建开始时间"
            end-placeholder="创建结束时间">
          </el-date-picker>
        </el-form-item>
        <el-row>
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item>
          <el-form-item>
            <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
          </el-form-item>
          <el-form-item style="float: right">
            <el-button-group>
              <el-tooltip content="刷新" placement="top">
                <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
              </el-tooltip>
              <el-tooltip content="列显示" placement="top">
                <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
              </el-tooltip>
              <el-tooltip content="导出" placement="top">
                <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
              </el-tooltip>
            </el-button-group>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table
      :height="350"
      :data="pageResult"
      :columns="filterColumns"
      @findPage="findPage"
      :showOperation="false"
      :showBatchDelete="false"
      :showSelection="false"
      ref="CyTable"
    ></cy-table>
  </div>
</template>

<script>
import CyTable from "@/views/Core/CyTable";
import KtButton from "@/views/Core/KtButton";
import { format } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
export default {
  components: {
    CyTable,
    KtButton,
    TableColumnFilterDialog
  },
  data() {
    return {
      size: "small",
      filters: {
        startTime: "",
        endTime: "",
        t: "orderIntegral",
        status: "",
        ordernumber: "",
        productname: "",
        customername: "",
        bname: "",
        recipient: "",
        time:""
      },
      columns: [
        { prop: "ordernumber", label: "订单编号", minWidth: 120 },
        { prop: "productname", label: "商品", minWidth: 100 },
        { prop: "customername", label: "客户名称", minWidth: 100 },
        { prop: "bname", label: "商家", minWidth: 80 },
        { prop: "recipient", label: "收件人", minWidth: 80 },
        { prop: "integral", label: "积分/数量", minWidth: 80 },
        { prop: "status", label: "发货状态", minWidth: 80 },
        { prop: "orderstatus", label: "订单状态", minWidth: 80 },
        { prop: "paystatus", label: "付款状态", minWidth: 80 },
        { prop: "create_time", label: "创建时间", minWidth: 120 }
	  ],
	  filterColumns:[],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {},

      operation: false, // true:新增, false:编辑
      editDialogVisible: false, // 新增编辑界面是否显示
      editLoading: false,

    };
  },
  methods: {
    // 获取分页数据
    findPage: function(data) {
      this.$refs.CyTable.findPage(this.filters);
    },
    chooseTimeRange(e) {
      this.filters.startTime=e[0]
      this.filters.endTime=e[1]
    },
    // 时间格式化
    dateFormat: function(row, column, cellValue, index) {
      return format(row[column.property]);
    },

    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
        this.filters.startTime="";
        this.filters.endTime="";
        this.findPage(null);
      }
    },

    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },
    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },
    // 处理表格列过滤显示
    initColumns: function() {
      let temp = [];

      $.each(this.columns, function(key, val) {
        temp.push(val);
      });
      this.filterColumns = temp;
    },
    //列表下载
    downloadExcel() {
      this.$confirm("确定下载列表文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let filename = "订单积分管理下载";
          this.$refs.CyTable.exportData(
            this.filters,
            this.filterColumns,
            filename
          );
        })
        .catch(() => {});
    }
  },
  mounted() {
	  this.initColumns()
  }
};
</script>

<style scoped>
</style>
